package com.group.controller;


import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import com.group.dao.CommentDao;
import com.group.dao.MediaDao;
import com.group.domain.Media;


/**
 * 起始界面（首页测试）
 */
@Controller
@RequestMapping(value = "/")
public class WelcomeController {
	
	MediaDao mediaDao = new MediaDao();
	CommentDao commentDao = new CommentDao();
	
	/**
	 * 用户访问主页，进行评分计算
	 * @param model
	 * @return	主页
	 */
	@RequestMapping(method = RequestMethod.GET)
	public String welcome(Model model) {
		List<Media> mediaList = mediaDao.findAllMedia();
		for (Media media : mediaList) {
			commentDao.averageRating(media);
		}
		return "redirect:home";
	}
}
